package edu.ccut.saturn.studio.naviagtor.wizard.model;

import java.io.File;
import java.util.List;

import edu.ccut.saturn.studio.core.util.wizard.SaturnWizard;

public class CreateModelWizard extends SaturnWizard {

	private String modelName = "";

	@Override
	protected String getEditorID() {
		return null;
	}

	@Override
	protected String getTemplatePath() {
		return "template/saturnfloder.ftl";
	}

	protected String getFileName() {
		return this.modelName
				+ super.getValues().get(
						CreateModelWizardPage.SATURN_FLODER_MODEL_FILE_NAME)
				+ File.separator + ".saturn";
	}

	public void addPages() {
		addPage(new CreateModelWizardPage());
	}

	@SuppressWarnings("unchecked")
	@Override
	public boolean performFinish() {
		super.initalValues();

		List<String> selects = (List<String>) super.getValues().get(
				CreateModelWizardPage.SATURN_FLODER_MODEL_SELECT);
		
		

		if (super.validate()) {
			super.generateFile();
			this.modelName = super.getValues().get(
					CreateModelWizardPage.SATURN_FLODER_MODEL_FILE_NAME)
					+ File.separator;

			if (selects != null) {
				for (String type : selects) {
					
//					String nameAndFileName =  SaturnModelTypes.getTypeDefaultFloderName(type);
					
					super.getValues()
							.put(CreateModelWizardPage.SATURN_FLODER_MODEL_TYPE,
									type);
					super.getValues().put(
							CreateModelWizardPage.SATURN_FLODER_MODEL_FILE_NAME,
//							SaturnModelTypes.getTypeDefaultFloderName(type));
//							nameAndFileName.substring(0, nameAndFileName.indexOf(",")));
							type);
					super.getValues().put(
							CreateModelWizardPage.SATURN_FLODER_MODEL_NAME, SaturnModelTypes.getTypeDefaultFloderName(type));
					super
							.getValues()
							.put(
									CreateModelWizardPage.SATURN_FLODER_MODEL_DESCRIPTION,
									"");

					super.generateFile();
				}
			}

			return true;
		}

		return false;
	}
}